/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.persistance;

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.IOException;
import nominalitzacions.domain.Settings;
import nominalitzacions.domain.UrlDomainController;

/**
 *
 * @author genis
 */
public class SettingsDataManagerController {
    private SettingsDataManager SDM;
    private UrlDomainController UDC;

    public SettingsDataManagerController() {
        UDC = new UrlDomainController();
        SDM = new SettingsDataManager(UDC.getConfig());
    }

    public Settings loadSettings(boolean def) throws FileNotFoundException {
        String [] setts = SDM.loadSettings(def);
        int n = Integer.parseInt(setts[0]);
        int k = Integer.parseInt(setts[1]);
        int rhc = Integer.parseInt(setts[2]);
        int ghc = Integer.parseInt(setts[3]);
        int bhc = Integer.parseInt(setts[4]);
        Color hc = new Color(rhc, ghc, bhc);

        int rbc = Integer.parseInt(setts[5]);
        int gbc = Integer.parseInt(setts[6]);
        int bbc = Integer.parseInt(setts[7]);
        Color bc = new Color(rbc, gbc, bbc);

        Settings settings = new Settings(n, k, hc, bc);

        return settings;
    }

    public boolean [] loadChecks() throws FileNotFoundException {
        String [] checks = SDM.loadChecks();
        boolean [] c = new boolean[3];
        for (int i = 0; i < c.length; ++i) {
            c[i] = Boolean.parseBoolean(checks[i]);
        }
        return c;
    }
    
    public void saveSettings(Settings settings) throws IOException {
        String [] setts = new String[8];
        setts[0] = String.valueOf(settings.getN());
        setts[1] = String.valueOf(settings.getK());
        setts[2] = String.valueOf(settings.getHighlight().getRed());
        setts[3] = String.valueOf(settings.getHighlight().getGreen());
        setts[4] = String.valueOf(settings.getHighlight().getBlue());
        setts[5] = String.valueOf(settings.getBackground().getRed());
        setts[6] = String.valueOf(settings.getBackground().getGreen());
        setts[7] = String.valueOf(settings.getBackground().getBlue());
        SDM.saveSettings(setts);
    }

    public void saveChecks(boolean [] c) throws IOException {
        String [] checks = new String[3];
        for (int i = 0; i < c.length; ++i) {
            checks[i] = String.valueOf(c[i]);
        }
        SDM.saveChecks(checks);
    }

}
